package com.example.controller;

import com.example.common.Result;
import com.example.entity.Positions;
import com.example.service.PositionsService;
import com.github.pagehelper.PageInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 职位类型接口
 **/
@RestController
@RequestMapping("/Positions")
public class PositionsController {

    @Resource
    private PositionsService positionsService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Positions positions) {
        positionsService.add(positions);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        positionsService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        positionsService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Positions positions) {
        positionsService.updateById(positions);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Positions positions = positionsService.selectById(id);
        return Result.success(positions);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Positions positions ) {
        List<Positions> list = positionsService.selectAll(positions);
        return Result.success(list);
    }
    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Positions positions,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Positions> page = positionsService.selectPage(positions, pageNum, pageSize);
        return Result.success(page);
    }
    /**
     * 根据职位类型ID查询所有职位名称
     */
    @GetMapping("/names/{id}")
    public Result getPositionNames(@PathVariable Integer id) {
        List<Positions> positionNames = positionsService.selectByPositionTypeId(id);
        return Result.success(positionNames);
    }
}